*This file creates the appendix tables in the paper
*******************************************************************************************
********************************************************************************
* TABLE A.1
********************************************************************************	
	
	****** insheet BDS data for entry stats
insheet using $datadir/raw/bds_e_szsic_release.csv, comma clear

keep if regexm(size, "h") | regexm(size, "i") | regexm(size, "g") 

keep if sic1==20 //manufacturing 
collapse (sum) estabs_entry, by(year size)
keep if year>=2002
rename year year 

g job_bin = 1 if regexm(size, "g")
replace job_bin = 2 if regexm(size, "h")
replace job_bin = 3 if  regexm(size, "i")

drop size 
reshape wide estabs_entry, i(year) j(job_bin) 

sa $temp/bds, replace 

u $datadir/subsidy_data, clear 
keep id jobs_direct naics2 year 
duplicates drop 
keep if naics2==31 //manufacturing 
g job_bin = 1 if jobs_direct<500
replace job_bin = 2 if inrange(jobs_direct, 500,999)
replace job_bin = 3 if jobs_direct>=1000

g estabs_sub=1
collapse (sum) estabs_sub, by(job_bin year)

reshape wide estabs_sub, i(year) j(job_bin)

merge 1:1 year using $temp/bds, keep(3) nogen 

	* MAKE TABLE
	g tab = "\begin{tabular}{lrrrrrr}" in 1
	g hline = " \hline" in 1 
	*Bottomrule
	g bot = "\bottomrule" in 1
	*End
	g end = "\end{tabular}" in 1
	*Panel

	g title1 = "  &  \multicolumn{3}{c}{Establishment Entry} & \multicolumn{3}{c}{Subsidy Data} \\ " in 1
	
		g title2 = "Year & 250-499 & 500-999 & 1000+ & $<$500 & 500-999 & 1000+ \\ " in 1

	g c = " "

local filename = "bds_v_subsidy"

	listtex tab if _n == 1 using "$appxdir/`filename'.tex", replace rstyle(none)
	listtex title1 if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)	
	listtex title2 if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)			
	listtex hline if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)			 
	listtex year estabs_entry1 estabs_entry2 estabs_entry3 estabs_sub1 estabs_sub2 estabs_sub3 ///
		, appendto("$appxdir/`filename'.tex") rstyle(tabular) 
	listtex hline if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)	
	listtex end if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)	
	


********************************************************************************
* TABLE A.2
********************************************************************************
// employment in t-1 
u $datadir/CBP_county_ind_n2, clear
collapse (sum) emp_n2, by(year fips)
replace year = year-1 
sa $temp/state_emp, replace  

//state chars
u $datadir/location_char, clear
collapse (sum) pop, by(stateabbrev statefip year corp term_limit)
duplicates drop 
sa $temp/state_char, replace 

//State level spending data [collected by the author]
	u $datadir/raw/state_level_spending, clear

	*Total economic development spending at the state level
	egen incentives = rowtotal(total_credits total_budget)
	drop *_credits *_budget

	keep if inrange(year,2007,2014)
	* merge corp tax, term limit 
	merge 1:1 stateabbrev year using $temp/state_char, keep(2 3) nogen
	
	rename statefip fips 
	*merge GDP
	merge 1:1 fips year using $datadir/raw/bea_state_gdp.dta, keep(3) nogen keepusing(GDP statename)
	
	* merge emp 
	merge 1:1 fips year using $temp/state_emp.dta, keep(3) nogen 
	
	*Adjust for inflation
	adjust_inflation GDP incentives, year(2017) 
	lab var GDP "GDP, Million 2017 USD"


	*data cleaning, normalize by population 
	foreach v in GDP incentives {
		g `v'_percap = `v'/pop
	}
	
	replace GDP_percap=GDP_percap*1000 /*gdp per cap in 1000s*/
		g epop = emp/pop 

	replace epop=epop*100
	
	sort fips year
	foreach v in incentives_percap GDP_percap epop {
		by fips: g d_`v'=`v' - `v'[_n-1]
	}

	local vlist " d_GDP_percap d_epop GDP_percap epop"
	sort fips year
	foreach v in `vlist' {
		by fips: g `v't1 = `v'[_n-1]
		}

	eststo clear
	foreach v in GDP_percap epop corprate {
		eststo: reghdfe incentives_percap `v', absorb(year fips)
		quietly summ incentives_percap if e(sample)==1
		estadd scalar dmean = r(mean)
		quietly summ `v' if e(sample)==1
		estadd scalar imean = r(mean)
	}
	eststo: reghdfe incentives_percap GDP_percap epop corprate, absorb(year fips)
	quietly summ incentives_percap if e(sample)==1
	estadd scalar dmean = r(mean)
	
	foreach v in d_GDP_percapt1 d_epopt1 term_limit {
		eststo: reghdfe d_incentive `v' , absorb(year fips)
		quietly summ d_incentive if e(sample)==1
		estadd scalar dmean = r(mean)
		quietly summ `v' if e(sample)==1
		estadd scalar imean = r(mean)
	}
	eststo: reghdfe d_incentive term_limit d_epopt1 d_GDP_percapt1 ,  ///
		absorb(year fips)
	quietly summ d_incentive if e(sample)==1
	estadd scalar dmean = r(mean)
		
		
	label var GDP_percap "GDP per capita (\textdollar1000)"
	label var epop "\% Population Employed"
	
	label var d_GDP_percapt1 "$\Delta_{t-1}$ GDP per capita"
	label var d_epopt1 "$\Delta_{t-1}$ \% Pop. Employed"
	label var term_limit "Term-limited Governor"
	label var corprate "Corporate tax rate (\%)"
	
	esttab using "$appxdir/statespendreg.tex", replace ///
		cells(b(star fmt(%-10.2fc)) se(par fmt(%-10.2fc)))	///
			noconstant		///
		stats(N r2 dmean imean, fmt(0 2 2 2)	///
		labels("Observations" "R-squared" "Dep. Var. Mean" "Ind. Var. Mean"))	nonumber	///
		label  collabels(none) mlabels(none) ///
		mgroup("Per Capita Incentives (\textdollar)" "$\Delta$ Per Capita Incentives (\textdollar)" , ///
		pattern(1 0 0 0 1 0 0 0 ) ///
		prefix(\multicolumn{@span}{c}{) suffix(}) ///
		span erepeat(\cmidrule(lr){@span})) substitute(\_ _)

********************************************************************************
**** Appendix Table H.1
********************************************************************************
*Runner-up places:
********************************************************************************
u $datadir/analysis_cz, clear
rename id_win id
	drop *_win

g sample2=(county!="")

keep if sample2 ==1 
keep id corp_tax income_tax proptax sales_tax /// taxes
wage incwage_top_5 e_ind e_comm FHFA /// costs 
indus_zoning r2w /// regulations 
freightrail auto_roadnetwork airport_any bad_bridge /// logistics/infrastructure 
pr_college top_RD occ_top2_naics3 sh_occ perc_est_n4 /// skilled labor/suppliers 
	term_limit ln_pinc unemp min_mindist density 
duplicates drop


foreach v in corp_tax income_tax proptax sales_tax /// taxes
wage incwage_top_5 e_ind e_comm FHFA /// costs 
indus_zoning r2w /// regulations 
freightrail auto_roadnetwork airport_any bad_bridge /// logistics/infrastructure 
pr_college top_RD occ_top2_naics3 sh_occ perc_est_n4 /// skilled labor/suppliers 
	term_limit ln_pinc unemp min_mindist density /// location chars 
	{
		g sd_`v'_2 = `v'
		g med_`v'_2 = `v'
		rename `v' mean_`v'_2
		}
	collapse (mean) mean_* (sd) sd_* (p50) med_*
	g match=1
tempfile samp2
sa `samp2'

* All places
********************************************************************************
u $datadir/analysis_cz, clear
rename id_win id
	drop *_win
keep id corp_tax income_tax proptax sales_tax /// taxes
wage incwage_top_5 e_ind e_comm FHFA /// costs 
indus_zoning r2w /// regulations 
freightrail auto_roadnetwork airport_any bad_bridge /// logistics/infrastructure 
pr_college top_RD occ_top2_naics3 sh_occ perc_est_n4 /// skilled labor/suppliers 
	term_limit ln_pinc unemp min_mindist density 

duplicates drop

foreach v in corp_tax income_tax proptax sales_tax /// taxes
wage incwage_top_5 e_ind e_comm FHFA /// costs 
indus_zoning r2w /// regulations 
freightrail auto_roadnetwork airport_any bad_bridge /// logistics/infrastructure 
pr_college top_RD occ_top2_naics3 sh_occ perc_est_n4 /// skilled labor/suppliers 
	term_limit ln_pinc unemp min_mindist density /// location chars 
	{
		g sd_`v'_3 = `v'
		g med_`v'_3 = `v'
		rename `v' mean_`v'_3
		}
	collapse (mean) mean_* (sd) sd_* (p50) med_*
	g match=1
tempfile samp3
sa `samp3'

* Winning places 
********************************************************************************
u $datadir/analysis_cz, clear

keep *_win
keep id corp_tax income_tax proptax sales_tax /// taxes
wage_win incwage_top_5 e_ind e_comm FHFA /// costs 
indus_zoning r2w /// regulations 
freightrail auto_roadnetwork airport_any bad_bridge /// logistics/infrastructure 
pr_college top_RD occ_top2_naics3 sh_occ perc_est_n4 /// skilled labor/suppliers 
	term_limit ln_pinc unemp min_mindist density 
	
duplicates drop

rename *_win *

foreach v in corp_tax income_tax proptax sales_tax /// taxes
wage incwage_top_5 e_ind e_comm FHFA /// costs 
indus_zoning r2w /// regulations 
freightrail auto_roadnetwork airport_any bad_bridge /// logistics/infrastructure 
pr_college top_RD occ_top2_naics3 sh_occ perc_est_n4 /// skilled labor/suppliers 
	term_limit ln_pinc unemp min_mindist density /// location cars 
	{
		g sd_`v'_1 = `v'
		g med_`v'_1 = `v'
		rename `v' mean_`v'_1
		}
	collapse (mean) mean_* (sd) sd_* (p50) med_*
	g match=1

merge 1:1 match using `samp2', keep(3) nogen
merge 1:1 match using `samp3', keep(3) nogen

	* Make table
	format sd_* mean_* med_* %12.2fc

	* MAKE TABLE
	g tab = "\begin{tabular}{lrrrrrrrrr}" in 1
	g top = "\toprule" in 1
	*Midrule
	g mid = " \midrule" in 1 
	g hline = " \hline" in 1 
	*Bottomrule
	g bot = "\bottomrule" in 1
	*End
	g end = "\end{tabular}" in 1
	*Panel

	g title1 = "  &  \multicolumn{3}{c}{Winners} & \multicolumn{3}{c}{Runner-ups}  & \multicolumn{3}{c}{All U.S.} \\ " in 1
	
		g title2 = " &  Mean & Med. & SD & Mean & Med. & SD & Mean & Med. & SD  \\ " in 1

	g c = " "
	
g label_corp_tax = "\hspace{5mm} Corporate Tax (\%)"
g label_income_tax = "\hspace{5mm} Income Tax (\%)"
g label_sales_tax = "\hspace{5mm} Sales Tax (\%)"
g label_proptax = "\hspace{5mm} Property Tax (\%)"

g label_FHFA =  "\hspace{5mm} Housing Prices (\\$1,000)"
g label_wage =  "\hspace{5mm} Industry Wage (\\$1,000)"
g label_incwage_top_5 = "\hspace{5mm} Relevant Occupation Wage (\\$1,000)"
g label_e_ind = "\hspace{5mm} Industrial Electricity Price (c/KwH)"
g label_e_comm = "\hspace{5mm} Commercial Electricity Price (c/KwH)"

g label_r2w = "\hspace{5mm} Right-to-Work"
g label_indus_zoning = "\hspace{5mm} Perceived Industrial Land Supply"

g label_bad_bridge =  "\hspace{5mm} Poor Condition Bridges (\%)"
g label_auto_roadnetwork = "\hspace{5mm}  Auto Network Density"
g label_airport_any =  "\hspace{5mm} Major Airport"
g label_freightrail=  "\hspace{5mm}  Freight Rail Density"

g label_pr_college = "\hspace{5mm} Population with BA+ (\%)"
g label_top_RD = "\hspace{5mm} Research University"

g label_perc_est_n4 = "\hspace{5mm} Share Industry Establishments "
g label_occ_top2_naics3 = "\hspace{5mm} Population in Relevant Occupations (1,000)"
g label_sh_occ = "\hspace{5mm} Population in Relevant Occupations (\%)"

g label_term_limit = "\hspace{5mm} Term-limited Gov."
g label_ln_pinc =  "\hspace{5mm} ln(Per Cap Income, \\$1000)"
g label_density = "\hspace{5mm} Density (1,000 Persons/Mile$^2$)"
g label_unemp = "\hspace{5mm} Unemployment Rate  (\%)"
g label_min_mindist =  "\hspace{5mm} Distance to State Border"


g state = "\textit{State-level:} & & & & & & & & & \\"
g loc = "\textit{State-CZ-level:} & & & & & & & & & \\"
g loc_firm = "\textit{State-CZ $\times$ Industry-level:} & & & & & & & & & \\"

*****Output
	local filename = "analysis_chars"

	listtex tab if _n == 1 using "$appxdir/`filename'.tex", replace rstyle(none)
	listtex title1 if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)		
	listtex title2 if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)	
	listtex hline if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)		
	listtex state if _n ==1, appendto("$appxdir/`filename'.tex") rstyle(none)	 
	foreach v in corp_tax income_tax sales_tax r2w e_ind e_comm term_limit  {
		listtex label_`v' mean_`v'_1 med_`v'_1 sd_`v'_1  mean_`v'_2  med_`v'_2  sd_`v'_2  ///
		mean_`v'_3  med_`v'_3  sd_`v'_3 ///
		, appendto("$appxdir/`filename'.tex") rstyle(tabular) 
		}
	listtex loc if _n ==1, appendto("$appxdir/`filename'.tex") rstyle(none)	
	foreach v in proptax FHFA indus_zoning bad_bridge auto_roadnetwork airport_any freightrail ///
	pr_college top_RD ln_pinc unemp density min_mindist    {
		listtex label_`v' mean_`v'_1 med_`v'_1 sd_`v'_1  mean_`v'_2  med_`v'_2  sd_`v'_2  ///
		mean_`v'_3  med_`v'_3  sd_`v'_3 ///
		, appendto("$appxdir/`filename'.tex") rstyle(tabular) 
		}
	listtex loc_firm if _n ==1, appendto("$appxdir/`filename'.tex") rstyle(none)	 
	foreach v in wage incwage_top_5 perc_est_n4 occ_top2_naics3 sh_occ {
		listtex label_`v' mean_`v'_1 med_`v'_1 sd_`v'_1  mean_`v'_2  med_`v'_2  sd_`v'_2  ///
		mean_`v'_3  med_`v'_3  sd_`v'_3 ///
		, appendto("$appxdir/`filename'.tex") rstyle(tabular) 
		}
		
	listtex hline if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)	
	
	listtex end if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)	

********************************************************************************
* Table D.1: Selection on Observed and Unobserved Variables 
********************************************************************************
u $datadir/analysis_cz, clear

eststo clear 

g label_diff_corp_tax = "$\Delta$ Corporate Tax (\%)"
g label_diff_corp_tax_invest  ="\hspace{4mm} $\times$ Investment Planned (\\$ B)"
g label_diff_income_tax = "$\Delta$ Income Tax (\%)"
g label_diff_income_tax_jobs = "\hspace{4mm} $\times$ Jobs Promised (1,000)"
g label_diff_sales_tax  ="$\Delta$ Sales Tax (\%)"
g label_diff_proptax  ="$\Delta$ Property Tax (\%)"
g label_diff_FHFA  ="$\Delta$ Housing Price (\\$1,000)"
g label_diff_wage  ="$\Delta$ Industry Wage (\\$1,000)"
g label_diff_incwage = "$\Delta$ Industry Wage (\\$1,000)"
g label_diff_e_ind_invest = "$\Delta$ Electricity Price (c/KwH) $\times$ Investment Planned (\\$ B)"
g label_diff_e_comm = "$\Delta$ Electricity Price (c/KwH)"
g label_diff_indus_zoning_invest = "$\Delta$ Industrial Land Supply $\times$ Investment Planned (\\$ B)"
g label_diff_r2w = "$\Delta$ Right-to-Work State"
g label_diff_auto_roadnetwork = "$\Delta$ Auto Network Density"
g label_diff_auto_roadnetwork_3 = "$\Delta$ Auto Network Density $\times$ Traditional Manufacturing "
g label_diff_airport_any  ="$\Delta$ Large Airport"
g label_diff_occ_top2_naics3  = "$\Delta$ Population in Relevant Occupations (1,000)"
g label_diff_occ_top2_naics3_jobs  =  "\hspace{4mm} $\times$ Jobs Promised (1,000)"
g label_diff_pr_college_1  = "$\Delta$ Population with BA+ (\%) $\times$ High-Tech Manufacturing"
g label_diff_pr_college_3 = "$\Delta$ Population with BA+ (\%) $\times$ Traditional Manufacturing"
g label_diff_perc_est_n4_1  ="$\Delta$ Industry Estab. Share (\%) $\times$ High-Tech Manufacturing "
g label_diff_top_RD = "$\Delta$ Research University" 
g label_R2 = "\multicolumn{1}{r}{R-squared:}"

g diff_corp_tax_invest = diff_corp_tax*invest_B
g diff_e_ind_invest  = diff_e_ind*invest_B 
g diff_indus_zoning_invest = diff_indus_zoning*invest_B 
g diff_auto_roadnetwork_3 = diff_auto_roadnetwork*(manuf_type==3)
g diff_occ_top2_naics3_jobs = diff_occ_top2_naics3*jobs_direct
g diff_pr_college_1 = diff_pr_college*(manuf_type==1)
g diff_pr_college_3 = diff_pr_college*(manuf_type==3)
g diff_perc_est_n4_1 = diff_perc_est_n4*(manuf_type==1)

unab manuf_vars: diff_corp_tax diff_corp_tax_invest diff_income_tax diff_proptax   /// 
	diff_wage  diff_e_ind_invest  diff_indus_zoning_invest diff_auto_roadnetwork_3 /// 
	diff_occ_top2_naics3 diff_occ_top2_naics3_jobs diff_pr_college_1 diff_pr_college_3 /// 
	diff_perc_est_n4_1

reg sub_M `manuf_vars' ///
	jobs_direct c.mult_jobs invest_B income_tax corp_tax ln_pinc term_limit unemp c.unemp#c.jobs_direct c.incwage_top_5 ///
	c.incwage_top_5#c.ln_pinc [pw=weight] if ru_limit==1 & manuf==1  & sub_M<1000 , noconstant robust
	
foreach v in `manuf_vars' { 
	g `v'_cont = _coef[`v']
	}
	
//predict profits so I can compare distribution with b* profits 
	g pi_cont_win = diff_corp_tax_cont*corp_tax_win + diff_corp_tax_invest_cont*corp_tax_win*invest_B + ///
	diff_income_tax_cont*income_tax_win + diff_proptax_cont*proptax_win +  /// 
	diff_wage_cont*wage_win + diff_e_ind_invest_cont*e_ind_win*invest_B +  ///
	diff_indus_zoning_invest_cont*indus_zoning_win*invest_B + diff_auto_roadnetwork_3_cont*auto_roadnetwork_win*(manuf_type==3) + /// 
	diff_occ_top2_naics3_cont*occ_top2_naics3_win + diff_occ_top2_naics3_jobs_cont*occ_top2_naics3_win*jobs_direct+ ///
	diff_pr_college_1_cont*pr_college_win*(manuf_type==1) + diff_pr_college_3_cont*pr_college_win*(manuf_type==3) + /// 
	diff_perc_est_n4_1_cont*perc_est_n4_win*(manuf_type==1) if e(sample)==1

g pi_cont_ru = diff_corp_tax_cont*corp_tax + diff_corp_tax_invest_cont*corp_tax*invest_B + ///
	diff_income_tax_cont*income_tax + diff_proptax_cont*proptax +  /// 
	diff_wage_cont*wage + diff_e_ind_invest_cont*e_ind*invest_B +  ///
	diff_indus_zoning_invest_cont*indus_zoning*invest_B + diff_auto_roadnetwork_3_cont*auto_roadnetwork*(manuf_type==3) + /// 
	diff_occ_top2_naics3_cont*occ_top2_naics3 + diff_occ_top2_naics3_jobs_cont*occ_top2_naics3*jobs_direct + ///
	diff_pr_college_1_cont*pr_college*(manuf_type==1) + diff_pr_college_3_cont*pr_college*(manuf_type==3) + /// 
	diff_perc_est_n4_1_cont*perc_est_n4*(manuf_type==1) if e(sample)==1

preserve
	keep pi_cont* id_win 
	drop if pi_cont_win==. 
	g i=_n 
	reshape long pi_cont_, i(i id_win) string 
	drop i 
	duplicates drop 
	rename pi_cont_ pi_controlled 
	summ pi_controlled, det
		local control_min = `r(min)'
	replace pi_controlled = pi_controlled - `control_min'
	g i=_n
	sa $temp/pi_control, replace 
restore 
	

g R2_cont = `e(r2)'

reg sub_M  `manuf_vars' ///
	[pw=weight] if ru_limit==1 & manuf==1  & sub_M<1000 , noconstant robust

foreach v in `manuf_vars' { 
	g `v'_uncont = _coef[`v']
	}

g R2_uncont = `e(r2)'

*beta star: 
foreach v in `manuf_vars' { 
	g `v'_beta = `v'_cont - (`v'_uncont - `v'_cont)*(1-R2_cont)/(R2_cont-R2_uncont)
	g `v'_min = min(`v'_cont, `v'_beta)
	g `v'_max = max(`v'_cont, `v'_beta)
	}

	g pi_b_win = diff_corp_tax_beta*corp_tax_win + diff_corp_tax_invest_beta*corp_tax_win*invest_B + ///
	diff_income_tax_beta*income_tax_win + diff_proptax_beta*proptax_win +  /// 
	diff_wage_beta*wage_win + diff_e_ind_invest_beta*e_ind_win*invest_B +  ///
	diff_indus_zoning_invest_beta*indus_zoning_win*invest_B + diff_auto_roadnetwork_3_beta*auto_roadnetwork_win*(manuf_type==3) + /// 
	diff_occ_top2_naics3_beta*occ_top2_naics3_win + diff_occ_top2_naics3_jobs_beta*occ_top2_naics3_win*jobs_direct+ ///
	diff_pr_college_1_beta*pr_college_win*(manuf_type==1) + diff_pr_college_3_beta*pr_college_win*(manuf_type==3) + /// 
	diff_perc_est_n4_1_beta*perc_est_n4_win*(manuf_type==1) if e(sample)==1

g pi_b_ru = diff_corp_tax_beta*corp_tax + diff_corp_tax_invest_beta*corp_tax*invest_B + ///
	diff_income_tax_beta*income_tax + diff_proptax_beta*proptax +  /// 
	diff_wage_beta*wage + diff_e_ind_invest_beta*e_ind*invest_B +  ///
	diff_indus_zoning_invest_beta*indus_zoning*invest_B + diff_auto_roadnetwork_3_beta*auto_roadnetwork*(manuf_type==3) + /// 
	diff_occ_top2_naics3_beta*occ_top2_naics3 + diff_occ_top2_naics3_jobs_beta*occ_top2_naics3*jobs_direct + ///
	diff_pr_college_1_beta*pr_college*(manuf_type==1) + diff_pr_college_3_beta*pr_college*(manuf_type==3) + /// 
	diff_perc_est_n4_1_beta*perc_est_n4*(manuf_type==1) if e(sample)==1
		
preserve
	keep pi_b_* id_win 
	drop if pi_b_win==. 
	g i=_n 
	reshape long pi_b_, i(i id_win) string 
	drop i 
	duplicates drop 
	rename pi_b_ pi_betastar
	summ pi_b, det
	replace pi_betastar = pi_betastar - `control_min'
	g i=_n
	
	merge 1:1 id_win i using $temp/pi_control 

	summ pi_control 
	summ pi_beta 
	twoway (kdensity pi_control if pi_control<1200) (kdensity pi_beta if pi_beta<1200, lpattern(dash)) , xlabel(0(200)1200) xtitle("predicted profits ({c $|}M)") legend(order(1 "Baseline" 2 "Oster (2019) adjustment"))
	graph export $appxdir/oster_manuf.eps, replace 
restore 	
	
	keep *_cont *_uncont *_beta label* *_min *_max 
duplicates drop 

****NOW MAKE TABLE 
		
	* Make table
	format *_cont *_uncont *_beta %12.2fc

	*identified set: 
foreach v in `manuf_vars' { 
	g `v'_set = "[" + string(`v'_min, "%12.2fc") + ", " + string(`v'_max, "%12.2fc")+"]"
	}
	
	* MAKE TABLE
	g tab = "\begin{tabular}{lrrrl}" in 1
	g top = "\toprule" in 1
	*Midrule
	g mid = " \midrule" in 1 
	g hline = " \hline" in 1 

	*End
	g end = "\end{tabular}" in 1
	*Panel
	
	g title0 =  "  \multicolumn{5}{c}{\textbf{Manufacturing}} \\"
	g title1 =  " &  &  &   \multicolumn{2}{c}{Oster (2019)} \\"
	g title2 = "  &  \multicolumn{1}{c}{$\beta_{\text{controlled}}$} &  \multicolumn{1}{c}{$\beta_{\text{uncontrolled}}$} & \multicolumn{1}{c}{$\beta^*$} &  \multicolumn{1}{c}{Identified Set} \\ " in 1
	
	g c = " "
	
*****Output
	local filename = "oster_all"

	listtex tab if _n == 1 using "$appxdir/`filename'.tex", replace rstyle(none)
	listtex title0 if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)		
	listtex title1 if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)		
	listtex title2 if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)	
	listtex hline if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)	
	foreach v in `manuf_vars' {
		listtex label_`v' `v'_cont `v'_uncont `v'_beta `v'_set ///
		, appendto("$appxdir/`filename'.tex") rstyle(tabular) 
	}
		listtex hline if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)
	listtex label_R2 R2_cont R2_uncont c c , appendto("$appxdir/`filename'.tex") rstyle(tabular) 
	listtex hline if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)	

********************************************************************************
*SERVICES

u $datadir/analysis_cz, clear

eststo clear 

g label_diff_corp_tax = "$\Delta$ Corporate Tax (\%)"
g label_diff_income_tax = "$\Delta$ Income Tax (\%)"
g label_diff_income_tax_jobs = "\hspace{4mm} $\times$ Jobs Promised (1,000)"
g label_diff_sales_tax  ="$\Delta$ Sales Tax (\%)"
g label_diff_proptax  ="$\Delta$ Property Tax (\%)"
g label_diff_FHFA  ="$\Delta$ Housing Price (\\$1,000)"
g label_diff_FHFA_invest  ="\hspace{4mm} $\times$ Investment Planned (\\$ B)"
g label_diff_wage  ="$\Delta$ Industry Wage (\\$1,000)"
g label_diff_incwage = "$\Delta$ Industry Wage (\\$1,000)"
g label_diff_e_comm = "$\Delta$ Electricity Price (c/KwH)"
g label_diff_incwage_top_5_0 = "$\Delta$ Industry Wage (\\$1,000) $\times$ High-Skill Services"
g label_diff_incwage_top_5_1 = "$\Delta$ Industry Wage (\\$1,000) $\times$ Trade and Other Services \hspace{70mm}"

g label_diff_r2w = "$\Delta$ Right-to-Work State"
g label_diff_auto_roadnetwork = "$\Delta$ Auto Network Density"
g label_diff_airport_trade  ="$\Delta$ Large Airport"
g label_diff_occ_top2_naics3  = "$\Delta$ Population in Relevant Occupations (1,000)"
g label_diff_occ_top2_naics3_jobs  =  "\hspace{4mm} $\times$ Jobs Promised (1,000)"
g label_diff_top_RD_0 = "$\Delta$ Research University $\times$ Services" 
g label_diff_top_RD_1 = "$\Delta$ Research University $\times$ Trade" 
g label_R2 = "\multicolumn{1}{r}{R-squared:}"

g diff_income_tax_jobs = diff_income_tax*jobs_direct 
g diff_incwage_top_5_1 = diff_incwage_top_5*(low_serv==1)
g diff_incwage_top_5_0 = diff_incwage_top_5*(low_serv==0)
g diff_FHFA_invest = diff_FHFA*invest_B
g diff_airport_trade = diff_airport_any*(trade==1)
g diff_top_RD_0 = diff_top_RD*(trade==0)
g diff_top_RD_1 = diff_top_RD*(trade==1)
 
unab serv_vars: diff_corp_tax diff_income_tax diff_proptax  diff_income_tax_jobs  ///
diff_incwage_top_5_0 diff_incwage_top_5_1 diff_FHFA diff_FHFA_invest diff_e_comm  /// 
 diff_r2w diff_auto_roadnetwork diff_airport_trade diff_top_RD_0 diff_top_RD_1


reg sub_M `serv_vars' ///
	 c.jobs_direct mult_tot  c.invest_B income_tax corp_tax sales_tax proptax term_limit  unemp  incwage_top_5 ln_pinc  [pw=weight] if ru_limit==1 & manuf==0  & sub_M<400 , noconstant robust

foreach v in `serv_vars' { 
	g `v'_cont = _coef[`v']
	}
	
g R2_cont = `e(r2)'

g pi_cont_win = diff_corp_tax_cont*corp_tax_win + diff_income_tax_cont*income_tax_win  + ///
	diff_income_tax_jobs_cont*income_tax_win*jobs_direct + diff_proptax_cont*proptax_win +  /// 
	diff_incwage_top_5_0_cont*incwage_top_5_win*(low_serv==0) + diff_incwage_top_5_1_cont*incwage_top_5_win*(low_serv==1) + ///
	diff_FHFA_cont*FHFA_win + diff_FHFA_invest_cont*FHFA_win*invest_B + diff_e_comm_cont*e_comm_win +  ///
	diff_r2w_cont*r2w_win + diff_auto_roadnetwork_cont*auto_roadnetwork_win + /// 
	diff_airport_trade_cont*airport_any_win*(trade==1) + diff_top_RD_0_cont*top_RD_win*(trade==0) + ///
	diff_top_RD_0_cont*top_RD_win*(trade==1) if e(sample)==1

g pi_cont_ru = diff_corp_tax_cont*corp_tax + diff_income_tax_cont*income_tax + ///
	diff_income_tax_jobs_cont*income_tax*jobs_direct + diff_proptax_cont*proptax +  /// 
	diff_incwage_top_5_0_cont*incwage_top_5*(low_serv==0) + diff_incwage_top_5_1_cont*incwage_top_5*(low_serv==1) + ///
	diff_FHFA_cont*FHFA + diff_FHFA_invest_cont*FHFA*invest_B + diff_e_comm_cont*e_comm +  ///
	diff_r2w_cont*r2w + diff_auto_roadnetwork_cont*auto_roadnetwork + /// 
	diff_airport_trade_cont*airport_any*(trade==1) + diff_top_RD_0_cont*top_RD*(trade==0) + ///
	diff_top_RD_0_cont*top_RD*(trade==1) if e(sample)==1

preserve
	keep pi_cont* id_win 
	drop if pi_cont_win==. 
	g i=_n 
	reshape long pi_cont_, i(i id_win) string 
	drop i 
	duplicates drop 
	rename pi_cont_ pi_controlled 
	summ pi_controlled, det
	local control_min = `r(min)'
	replace pi_controlled = pi_controlled - `control_min'
	g i=_n
	sa $temp/pi_control, replace 
restore 
	

reg sub_M  `serv_vars' ///
	[pw=weight] if ru_limit==1 & manuf==0  & sub_M<400 , noconstant robust

foreach v in `serv_vars' { 
	g `v'_uncont = _coef[`v']
	}

g R2_uncont = `e(r2)'

*beta star: 
foreach v in `serv_vars' { 
	g `v'_beta = `v'_cont - (`v'_uncont - `v'_cont)*(1-R2_cont)/(R2_cont-R2_uncont)
	g `v'_min = min(`v'_cont, `v'_beta)
	g `v'_max = max(`v'_cont, `v'_beta)
	}

g pi_b_win = diff_corp_tax_beta*corp_tax_win + diff_income_tax_beta*income_tax_win  + ///
	diff_income_tax_jobs_beta*income_tax_win*jobs_direct + diff_proptax_beta*proptax_win +  /// 
	diff_incwage_top_5_0_beta*incwage_top_5_win*(low_serv==0) + diff_incwage_top_5_1_beta*incwage_top_5_win*(low_serv==1) + ///
	diff_FHFA_beta*FHFA_win + diff_FHFA_invest_beta*FHFA_win*invest_B + diff_e_comm_beta*e_comm_win +  ///
	diff_r2w_beta*r2w_win + diff_auto_roadnetwork_beta*auto_roadnetwork_win + /// 
	diff_airport_trade_beta*airport_any_win*(trade==1) + diff_top_RD_0_beta*top_RD_win*(trade==0) + ///
	diff_top_RD_0_beta*top_RD_win*(trade==1) if e(sample)==1

g pi_b_ru = diff_corp_tax_beta*corp_tax + diff_income_tax_beta*income_tax + ///
	diff_income_tax_jobs_beta*income_tax*jobs_direct + diff_proptax_beta*proptax +  /// 
	diff_incwage_top_5_0_beta*incwage_top_5*(low_serv==0) + diff_incwage_top_5_1_beta*incwage_top_5*(low_serv==1) + ///
	diff_FHFA_beta*FHFA + diff_FHFA_invest_beta*FHFA*invest_B + diff_e_comm_beta*e_comm +  ///
	diff_r2w_beta*r2w + diff_auto_roadnetwork_beta*auto_roadnetwork + /// 
	diff_airport_trade_beta*airport_any*(trade==1) + diff_top_RD_0_beta*top_RD*(trade==0) + ///
	diff_top_RD_0_beta*top_RD*(trade==1) if e(sample)==1

preserve
	keep pi_b_* id_win 
	drop if pi_b_win==. 
	g i=_n 
	reshape long pi_b_, i(i id_win) string 
	drop i 
	duplicates drop 
	rename pi_b_ pi_betastar
	summ pi_b, det
	replace pi_betastar = pi_betastar - `control_min'
	g i=_n
	
	merge 1:1 id_win i using $temp/pi_control 
summ pi_beta 
summ pi_control 
	twoway (kdensity pi_control) (kdensity pi_beta if pi_beta>0, lpattern(dash)) , xlabel(0(50)450) xtitle("predicted profits ({c $|}M)") legend(order(1 "Baseline" 2 "Oster (2019) adjustment"))
	graph export $appxdir/oster_serv.eps, replace 

restore 	
	
keep *_cont *_uncont label*  *_min *_max *_beta
duplicates drop 
****NOW MAKE TABLE 
		
	* Make table
	format *_cont *_uncont *_beta %12.2fc

	*identified set: 
foreach v in `serv_vars' { 
	g `v'_set = "[" + string(`v'_min, "%12.2fc") + ", " + string(`v'_max, "%12.2fc")+"]"
	}
	
	* MAKE TABLE
	g tab = "\begin{tabular}{lrrrl}" in 1
	g top = "\toprule" in 1
	*Midrule
	g mid = " \midrule" in 1 
	g hline = " \hline" in 1 

	*End
	g end = "\end{tabular}" in 1
	*Panel

	
	g title0 =  "  \multicolumn{5}{c}{\textbf{Trade/Services}} \\"
	g title1 =  " &  &  &   \multicolumn{2}{c}{Oster (2019)} \\"
	g title2 = "  &  \multicolumn{1}{c}{$\beta_{\text{controlled}}$} &  \multicolumn{1}{c}{$\beta_{\text{uncontrolled}}$} & \multicolumn{1}{c}{$\beta^*$} &  \multicolumn{1}{c}{Identified Set} \\ " in 1
	
	g c = " "
	

*****Output
	listtex c c c c c, appendto("$appxdir/`filename'.tex") rstyle(tabular)  
	listtex title0 if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)		
	listtex title1 if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)		
	listtex title2 if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)	
	listtex hline if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)	
	foreach v in `serv_vars' {
		listtex label_`v' `v'_cont `v'_uncont `v'_beta `v'_set ///
		, appendto("$appxdir/`filename'.tex") rstyle(tabular) 
	}
		listtex hline if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)
	listtex label_R2 R2_cont R2_uncont c c , appendto("$appxdir/`filename'.tex") rstyle(tabular) 
	listtex hline if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)	
	listtex end if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)	 



/*****************************************************************************
Tab. E.1: Differences in location attributes 
*****************************************************************************/
u $datadir/analysis_cz_long, clear

unab econ_dstats: corp_tax income_tax proptax sales_tax  wage incwage_top_5 FHFA e_comm e_ind ///
	r2w indus_zoning auto_roadnetwork airport_any  /// 
	occ_top2_naics3  perc_est_n4 pr_college top_RD /// 
	ln_pinc term_limit unemp 

keep winner runnerup `econ_dstats' 

****** Table Stats
*Winning d-stats
preserve
keep if winner==1
	foreach v in `econ_dstats'  {
			g sd_`v'_1 = `v'
			g p50_`v'_1 = `v'
			rename `v' mean_`v'_1
			}
			g n_1=1
		collapse (mean) mean_* (sd) sd_* (sum) n_* (p50) p50_*
		g match=1
	sa $temp/win, replace 
restore 

*Runner-up d-stats
preserve
	keep if runnerup==1
	foreach v in `econ_dstats'  {
			g sd_`v'_3 = `v'
			g p50_`v'_3 = `v'
			rename `v' mean_`v'_3
			}
			g n_3=1
		collapse (mean) mean_* (sd) sd_* (sum) n_* (p50) p50_*
		g match=1
	sa $temp/ru, replace 
restore 


*Runner-up ttest
	keep if win==1 | runnerup==1
		foreach v in `econ_dstats'   {
			ttest `v', by(win) unequal
			g diff_`v'_3 = r(mu_1)-r(mu_2)
			g t_`v'_3 = r(t)
			g star_`v'_3 = "*" if r(p)<.01/20 //bonferroni correction for number of t-tests
			replace star_`v'_3 = "**" if r(p)<.005/20 //bonferroni correction for number of t-tests
			replace star_`v'_3 = "***" if r(p)<.001/20 //bonferroni correction for number of t-tests
		}

	keep diff_* t_* star_*
	duplicates drop 
	g match=1


merge 1:1 match using $temp/win, keep(3) nogen
merge 1:1 match using $temp/ru, keep(3) nogen


		foreach v in `econ_dstats'   {
			g diffp50_`v'_3 = p50_`v'_3 - p50_`v'_1
		}
		
		
	* Make table
	format sd_* mean_* p50_* diff_* diffp50* t_* %12.2fc
	format n_* %12.0fc

	* MAKE TABLE
	g tab = "\begin{tabular}{lccccccccc}" in 1
	g top = "\toprule" in 1
	*Midrule
	g mid = " \midrule" in 1 
	g hline = " \hline" in 1 

	*End
	g end = "\end{tabular}" in 1
	*Panel

	g title0 =  " &  \multicolumn{3}{c}{Winners} &   \multicolumn{3}{c}{Runner-ups} &   \multicolumn{3}{c}{Difference} \\"
	g title1 = "  &  \multicolumn{1}{c}{Mean} &  \multicolumn{1}{c}{Med.} & \multicolumn{1}{c}{SD} &  \multicolumn{1}{c}{Mean} &  \multicolumn{1}{c}{Med.} & \multicolumn{1}{c}{SD} &  \multicolumn{1}{c}{Mean} &  \multicolumn{1}{c}{Med.} & \multicolumn{1}{c}{t-stat} \\ " in 1
	
	g c = " "
	g n_t=" "
	
g label_unemp = "Unemployment (\%)"
g label_ln_pinc = "log(Personal Income Per Capita)"
g label_FHFA= "Average Housing Price (\\$1,000)"
g label_corp_tax = "Corporate Tax (\%)"
g label_income_tax = "Income Tax (\%)"
g label_proptax = "Property Tax (\%)"
g label_sales_tax = "Sales Tax (\%)"
g label_wage = "Industry Wage (\\$1,000)"
g label_incwage_top_5 = "Relevant Occupation Wage (\\$1,000)"
g label_e_comm = "Commercial Electricity Price (c/KwH)"
g label_e_ind = "Industrial Electricity Price (c/KwH)"
g label_r2w = "Right-to-Work State"
g label_indus_zoning = "Industrial Land Supply"
g label_auto_roadnetwork = "Auto Network Density"
g label_airport_any = "Large Airport"
g label_occ_top2_naics3 = "Pop. in Relevant Occupation (1,000)"
g label_perc_est_n4 = "Industry Establishment Share (\%)"
g label_pr_college = "Population with BA+ (\%)"
g label_top_RD = "Research University"
g label_term_limit = "Term Limit"
g label_obs = "Observations"


	foreach v in `econ_dstats'  {
		g diff_`v'_3s = string(diff_`v'_3, "%12.2fc" ) + star_`v'_3 
		}


*****Output
	local filename = "attribute_mean_diff"

	listtex tab if _n == 1 using "$appxdir/`filename'.tex", replace rstyle(none)
	listtex title0 if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)		
	listtex title1 if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)	
	listtex hline if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)	
	foreach v in `econ_dstats' {
		listtex label_`v' mean_`v'_1 p50_`v'_1 sd_`v'_1 mean_`v'_3 p50_`v'_3 sd_`v'_3  diff_`v'_3s  diffp50_`v'_3 t_`v'_3  ///
		, appendto("$appxdir/`filename'.tex") rstyle(tabular) 
	}
		listtex hline if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)
	listtex label_obs n_1  n_t n_t n_3 n_t n_t n_t n_t n_t, appendto("$appxdir/`filename'.tex") rstyle(tabular) 
	listtex hline if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)	
	listtex end if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)	 

*****************************************************************************
*Then do differences in attributes for subset where I observe all bidders
*****************************************************************************
u $datadir/analysis_cz_long, clear

unab econ_dstats: corp_tax income_tax proptax sales_tax  wage incwage_top_5 FHFA e_comm e_ind ///
	r2w indus_zoning auto_roadnetwork airport_any  /// 
	occ_top2_naics3  perc_est_n4 pr_college top_RD /// 
	ln_pinc term_limit unemp 
	
keep if winner==1 | runnerup==1
bys id_deal: g N=_N 
keep if N>2 

keep winner runnerup `econ_dstats' 

****** Table Stats
*Winning d-stats
preserve
keep if winner==1
	foreach v in `econ_dstats'  {
			g sd_`v'_1 = `v'
			g p50_`v'_1 = `v'
			rename `v' mean_`v'_1
			}
			g n_1=1
		collapse (mean) mean_* (sd) sd_* (sum) n_* (p50) p50_*
		g match=1
	sa $temp/win, replace 
restore 

*Runner-up d-stats
preserve
	keep if runnerup==1
	foreach v in `econ_dstats'  {
			g sd_`v'_3 = `v'
			g p50_`v'_3 = `v'
			rename `v' mean_`v'_3
			}
			g n_3=1
		collapse (mean) mean_* (sd) sd_* (sum) n_* (p50) p50_*
		g match=1
	sa $temp/ru, replace 
restore 


*Runner-up ttest
	keep if win==1 | runnerup==1
		foreach v in `econ_dstats'   {
			ttest `v', by(win) unequal
			g diff_`v'_3 = r(mu_1)-r(mu_2)
			g t_`v'_3 = r(t)
			g star_`v'_3 = "*" if r(p)<.01/20 //bonferroni correction for number of t-tests
			replace star_`v'_3 = "**" if r(p)<.005/20 //bonferroni correction for number of t-tests
			replace star_`v'_3 = "***" if r(p)<.001/20 //bonferroni correction for number of t-tests
		}

	keep diff_* t_* star_*
	duplicates drop 
	g match=1


merge 1:1 match using $temp/win, keep(3) nogen
merge 1:1 match using $temp/ru, keep(3) nogen


		foreach v in `econ_dstats'   {
			g diffp50_`v'_3 = p50_`v'_3 - p50_`v'_1
		}
		
		
	* Make table
	format sd_* mean_* p50_* diff_* diffp50* t_* %12.2fc
	format n_* %12.0fc

	* MAKE TABLE
	g tab = "\begin{tabular}{lccccccccc}" in 1
	g top = "\toprule" in 1
	*Midrule
	g mid = " \midrule" in 1 
	g hline = " \hline" in 1 

	*End
	g end = "\end{tabular}" in 1
	*Panel

	g title0 =  " &  \multicolumn{3}{c}{Winners} &   \multicolumn{3}{c}{Runner-ups} &   \multicolumn{3}{c}{Difference} \\"
	g title1 = "  &  \multicolumn{1}{c}{Mean} &  \multicolumn{1}{c}{Med.} & \multicolumn{1}{c}{SD} &  \multicolumn{1}{c}{Mean} &  \multicolumn{1}{c}{Med.} & \multicolumn{1}{c}{SD} &  \multicolumn{1}{c}{Mean} &  \multicolumn{1}{c}{Med.} & \multicolumn{1}{c}{t-stat} \\ " in 1
	
	g c = " "
	g n_t=" "
	
g label_unemp = "Unemployment (\%)"
g label_ln_pinc = "log(Personal Income Per Capita)"
g label_FHFA= "Average Housing Price (\\$1,000)"
g label_corp_tax = "Corporate Tax (\%)"
g label_income_tax = "Income Tax (\%)"
g label_proptax = "Property Tax (\%)"
g label_sales_tax = "Sales Tax (\%)"
g label_wage = "Industry Wage (\\$1,000)"
g label_incwage_top_5 = "Relevant Occupation Wage (\\$1,000)"
g label_e_comm = "Commercial Electricity Price (c/KwH)"
g label_e_ind = "Industrial Electricity Price (c/KwH)"
g label_r2w = "Right-to-Work State"
g label_indus_zoning = "Industrial Land Supply"
g label_auto_roadnetwork = "Auto Network Density"
g label_airport_any = "Large Airport"
g label_occ_top2_naics3 = "Pop. in Relevant Occupation (1,000)"
g label_perc_est_n4 = "Industry Establishment Share (\%)"
g label_pr_college = "Population with BA+ (\%)"
g label_top_RD = "Research University"
g label_term_limit = "Term Limit"
g label_obs = "Observations"


	foreach v in `econ_dstats'  {
		g diff_`v'_3s = string(diff_`v'_3, "%12.2fc" ) + star_`v'_3 
		}


*****Output
	local filename = "attribute_mean_diff_v2"

	listtex tab if _n == 1 using "$appxdir/`filename'.tex", replace rstyle(none)
	listtex title0 if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)		
	listtex title1 if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)	
	listtex hline if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)	
	foreach v in `econ_dstats' {
		listtex label_`v' mean_`v'_1 p50_`v'_1 sd_`v'_1 mean_`v'_3 p50_`v'_3 sd_`v'_3  diff_`v'_3s  diffp50_`v'_3 t_`v'_3  ///
		, appendto("$appxdir/`filename'.tex") rstyle(tabular) 
	}
		listtex hline if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)
	listtex label_obs n_1  n_t n_t n_3 n_t n_t n_t n_t n_t, appendto("$appxdir/`filename'.tex") rstyle(tabular) 
	listtex hline if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)	
	listtex end if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)	 
	
*****************************************************************************
*Table E.2: Differences in Location Attributes: Bidders vs. All Locations
*****************************************************************************
u $datadir/analysis_cz_long, clear

unab econ_dstats: corp_tax income_tax proptax sales_tax  wage incwage_top_5 FHFA e_comm e_ind ///
	r2w indus_zoning auto_roadnetwork airport_any  /// 
	occ_top2_naics3  perc_est_n4 pr_college top_RD /// 
	ln_pinc term_limit unemp 
	
keep winner runnerup `econ_dstats' 

****** Table Stats
*Winner/runnerup d-stats
preserve
keep if winner==1 | runnerup==1
	foreach v in `econ_dstats'  {
			g sd_`v'_1 = `v'
			g p50_`v'_1 = `v'
			rename `v' mean_`v'_1
			}
			g n_1=1
		collapse (mean) mean_* (sd) sd_* (sum) n_* (p50) p50_*
		g match=1
	sa $temp/win, replace 
restore 

*Runner-up d-stats
preserve
	drop if winner==1 | runnerup==1
	foreach v in `econ_dstats'  {
			g sd_`v'_3 = `v'
			g p50_`v'_3 = `v'
			rename `v' mean_`v'_3
			}
			g n_3=1
		collapse (mean) mean_* (sd) sd_* (sum) n_* (p50) p50_*
		g match=1
	sa $temp/ru, replace 
restore 


*Runner-up ttest
g event = (winner==1 | runnerup==1)
		foreach v in `econ_dstats'   {
			ttest `v', by(event) unequal
			g diff_`v'_3 = r(mu_1)-r(mu_2)
			g t_`v'_3 = r(t)
			g star_`v'_3 = "*" if r(p)<.01/20 //bonferroni correction for number of t-tests
			replace star_`v'_3 = "**" if r(p)<.005/20 //bonferroni correction for number of t-tests
			replace star_`v'_3 = "***" if r(p)<.001/20 //bonferroni correction for number of t-tests
		}

	keep diff_* t_* star_*
	duplicates drop 
	g match=1


merge 1:1 match using $temp/win, keep(3) nogen
merge 1:1 match using $temp/ru, keep(3) nogen


		foreach v in `econ_dstats'   {
			g diffp50_`v'_3 = p50_`v'_3 - p50_`v'_1
		}
		
		
	* Make table
	format sd_* mean_* p50_* diff_* diffp50* t_* %12.2fc
	format n_* %12.0fc

	* MAKE TABLE
	g tab = "\begin{tabular}{lccccccccc}" in 1
	g top = "\toprule" in 1
	*Midrule
	g mid = " \midrule" in 1 
	g hline = " \hline" in 1 

	*End
	g end = "\end{tabular}" in 1
	*Panel

	g title0 =  " &  \multicolumn{3}{c}{Winners \& Runner-ups} &   \multicolumn{3}{c}{All Other Locations} &   \multicolumn{3}{c}{Difference} \\"
	g title1 = "  &  \multicolumn{1}{c}{Mean} &  \multicolumn{1}{c}{Med.} & \multicolumn{1}{c}{SD} &  \multicolumn{1}{c}{Mean} &  \multicolumn{1}{c}{Med.} & \multicolumn{1}{c}{SD} &  \multicolumn{1}{c}{Mean} &  \multicolumn{1}{c}{Med.} & \multicolumn{1}{c}{t-stat} \\ " in 1
	
	g c = " "
	g n_t=" "
	
g label_unemp = "Unemployment (\%)"
g label_ln_pinc = "log(Personal Income Per Capita)"
g label_FHFA= "Average Housing Price (\\$1,000)"
g label_corp_tax = "Corporate Tax (\%)"
g label_income_tax = "Income Tax (\%)"
g label_proptax = "Property Tax (\%)"
g label_sales_tax = "Sales Tax (\%)"
g label_wage = "Industry Wage (\\$1,000)"
g label_incwage_top_5 = "Relevant Occupation Wage (\\$1,000)"
g label_e_comm = "Commercial Electricity Price (c/KwH)"
g label_e_ind = "Industrial Electricity Price (c/KwH)"
g label_r2w = "Right-to-Work State"
g label_indus_zoning = "Industrial Land Supply"
g label_auto_roadnetwork = "Auto Network Density"
g label_airport_any = "Large Airport"
g label_occ_top2_naics3 = "Pop. in Relevant Occupation (1,000)"
g label_perc_est_n4 = "Industry Establishment Share (\%)"
g label_pr_college = "Population with BA+ (\%)"
g label_top_RD = "Research University"
g label_term_limit = "Term Limit"
g label_obs = "Observations"

	foreach v in `econ_dstats'  {
		g diff_`v'_3s = string(diff_`v'_3, "%12.2fc" ) + star_`v'_3 
		}

*****Output
	local filename = "attribute_mean_diff_v3"

	listtex tab if _n == 1 using "$appxdir/`filename'.tex", replace rstyle(none)
	listtex title0 if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)		
	listtex title1 if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)	
	listtex hline if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)	
	foreach v in `econ_dstats' {
		listtex label_`v' mean_`v'_1 p50_`v'_1 sd_`v'_1 mean_`v'_3 p50_`v'_3 sd_`v'_3  diff_`v'_3s  diffp50_`v'_3 t_`v'_3  ///
		, appendto("$appxdir/`filename'.tex") rstyle(tabular) 
	}
		listtex hline if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)
	listtex label_obs n_1  n_t n_t n_3 n_t n_t n_t n_t n_t, appendto("$appxdir/`filename'.tex") rstyle(tabular) 
	listtex hline if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)	
	listtex end if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)	 

*******************************************************************************
* Tables H.2 and H.3
*******************************************************************************	
	
u $datadir/analysis_cz, clear

eststo clear 
rename present_ru present 
label var diff_corp_tax "$\Delta$ Corporate Tax (\%)"
label var diff_income_tax "$\Delta$ Income Tax (\%)"
label var diff_sales_tax "$\Delta$ Sales Tax (\%)"
label var diff_proptax "$\Delta$ Property Tax (\%)"
label var diff_FHFA "$\Delta$ Housing Price (\\$1,000)"
label var diff_wage "$\Delta$ Industry Wage (\\$1,000)"
label var diff_incwage "$\Delta$ Industry Wage (\\$1,000)"
label var diff_e_ind "$\Delta$ Industrial Electricity Price (c/KwH)"
label var diff_e_comm "$\Delta$ Commercial Electricity Price (c/KwH)"
label var diff_indus_zoning "$\Delta$ Perceived Industrial Land Supply"
label var diff_r2w "$\Delta$ Right-to-Work State"
label var diff_bad_bridges "$\Delta$ Poor Condition Bridges (\%)"
label var diff_auto_roadnetwork "$\Delta$ Auto Network Density"
label var diff_freightrail "$\Delta$ Freight Rail Density"
label var diff_airport_any "$\Delta$ Large Airport"
label var diff_occ_top2_naics3 "$\Delta$ Population in Relevant Occupations (1,000)"
label var diff_pr_college "$\Delta$ Population with BA+ (\%)"
label var diff_perc_est_n4 "$\Delta$ Industry Establishment Share (\%)"
label var diff_top_RD "$\Delta$ Research University" 

label var jobs_direct "Jobs Promised (1,000)"
label var corp_tax "Corporate Tax (\%)"
label var income_tax "Income Tax (\%)"
label var sales_tax "Sales Tax (\%)"
label var proptax "Property Tax (\%)"
label var mult_supp "Industry Multipler"
label var invest_B "Investment Planned (\\$ B)"
label var unemp "Unemployment Rate (\%)"
label var incwage_top_5 "Relevant Occupation Wage (\\$1,000)"
label var term_limit "Term-limited Governor"
label var min_mindist "Distance to State Border"
label var present "Firm Presence in Runner-up Location"
label var density "Population (1,000) per Mile"
label var mult_jobs "Indirect Jobs (Jobs $\times$ Multiplier)"
label var ln_pinc  "Log(Personal Income per Capita)"
label var mult_tot "Industry Multiplier"

************START WITH ALL POSSIBLE VARIABLES 
eststo: reg sub_M ///
c.diff_corp_tax diff_income_tax c.diff_proptax c.diff_sales_tax  /// taxes
c.diff_FHFA diff_wage  c.diff_e_ind /// costs 
diff_indus_zoning diff_r2w /// regulations 
c.diff_freightrail c.diff_auto_roadnetwork   c.diff_bad_bridge  c.diff_airport_any /// logistics/infrastructure
c.diff_pr_college c.diff_occ_top2_naics3  /// skilled labor
c.diff_perc_est_n4  /// agglomeration/suppliers  
 jobs_direct mult_jobs  invest_B income_tax corp_tax sales_tax ///
 proptax term_limit unemp c.unemp#c.jobs_direct c.incwage_top_5##c.ln_pinc ///
 min_mindist present density [pw=weight] if ru_limit==1 & manuf==1  & sub_M<1000, noconstant robust
 estadd scalar obs = 200

************ADD ALL POTENTIAL INTERACTIONS
eststo:  reg sub_M c.diff_corp_tax diff_income_tax c.diff_proptax ///
c.diff_corp_tax#c.invest_B c.diff_income_tax#c.jobs_direct c.diff_proptax#c.invest_B diff_sales_tax  /// taxes
diff_wage c.diff_wage#c.jobs_direct diff_e_ind c.diff_e_ind#c.invest_B  c.diff_FHFA#i.manuf_type /// costs
c.diff_r2w#i.manuf_type c.diff_indus_zoning c.diff_indus_zoning#c.invest_B /// regulations 
c.diff_auto_roadnetwork#i.manuf_type  c.diff_bad_bridge#i.manuf_type  c.diff_freightrail#i.manuf_type  c.diff_airport_any#i.manuf_type /// logistics/infrastructure 
diff_occ_top2_naics3 c.diff_occ_top2_naics3#c.jobs_direct c.diff_pr_college#i.manuf_type /// skilled labor 
c.diff_perc_est_n4#i.manuf_type /// agglomeration/suppliers
jobs_direct mult_jobs invest_B income_tax corp_tax sales_tax proptax term_limit unemp ///
 c.unemp#c.jobs_direct c.incwage_top_5##c.ln_pinc min_mindist present density ///
 [pw=weight] if ru_limit==1 & manuf==1  & sub_M<1000, noconstant robust
estadd scalar obs = 200

************PARE DOWN
eststo:  reg sub_M ///
c.diff_corp_tax c.diff_corp_tax#c.invest_B diff_income_tax c.diff_proptax   /// taxes
diff_wage   c.diff_e_ind#c.invest_B  /// costs
 c.diff_indus_zoning#c.invest_B /// regulations 
c.diff_auto_roadnetwork#3.manuf_type /// logistics/infrastructure 
diff_occ_top2_naics3 c.diff_occ_top2_naics3#c.jobs_direct c.diff_pr_college#i.manuf_type /// skilled labor 
c.diff_perc_est_n4#1.manuf_type /// agglomeration/suppliers
jobs_direct c.mult_jobs invest_B income_tax corp_tax  term_limit unemp c.unemp#c.jobs_direct ln_pinc c.incwage_top_5 ///
c.incwage_top_5#c.ln_pinc [pw=weight] if ru_limit==1 & manuf==1  & sub_M<1000 , noconstant robust
estadd scalar obs = 200


esttab using "$appxdir/OLS_spec_manuf.tex", replace ///
		cells(b(star fmt(%-10.2fc)) & se(par fmt(%-10.2fc))) ///
		stats(obs r2 , fmt(%9.0fc %-10.3fc )	///
		labels( "Observations" "R-squared"))	///
		collabels(none) mlabels(none) label ///
		keep(diff_corp_tax c.diff_corp_tax#c.invest_B diff_income_tax c.diff_income_tax#c.jobs_direct /// 
		diff_proptax c.diff_proptax#c.invest_B diff_sales_tax /// 
		diff_wage c.diff_wage#c.jobs_direct diff_e_ind c.diff_e_ind#c.invest_B ///
		diff_FHFA 1.manuf_type#c.diff_FHFA 3.manuf_type#c.diff_FHFA /// 
		diff_r2w  1.manuf_type#c.diff_r2w 3.manuf_type#c.diff_r2w /// 
		diff_indus_zoning c.diff_indus_zoning#c.invest_B ///
		diff_auto_roadnetwork 1.manuf_type#c.diff_auto_roadnetwork 3.manuf_type#c.diff_auto_roadnetwork ///
		diff_bad_bridges ///
		diff_freightrail 1.manuf_type#c.diff_freightrail 3.manuf_type#c.diff_freightrail  ///
		diff_airport_any 1.manuf_type#c.diff_airport_any 3.manuf_type#c.diff_airport_any ///
		diff_occ_top2_naics3 c.diff_occ_top2_naics3#c.jobs_direct diff_pr_college ///
		1.manuf_type#c.diff_pr_college 3.manuf_type#c.diff_pr_college /// 
		diff_perc_est_n4 1.manuf_type#c.diff_perc_est_n4 3.manuf_type#c.diff_perc_est_n4 ///
		jobs_direct mult_jobs invest_B income_tax corp_tax sales_tax proptax term_limit ln_pinc  /// 
		incwage_top_5 unemp c.unemp#c.jobs_direct c.incwage_top_5#c.ln_pinc min_mindist present density) ///
		order(diff_corp_tax c.diff_corp_tax#c.invest_B diff_income_tax c.diff_income_tax#c.jobs_direct /// 
		diff_proptax c.diff_proptax#c.invest_B diff_sales_tax /// 
		diff_wage c.diff_wage#c.jobs_direct diff_e_ind c.diff_e_ind#c.invest_B ///
		diff_FHFA 1.manuf_type#c.diff_FHFA 3.manuf_type#c.diff_FHFA /// 
		diff_r2w  1.manuf_type#c.diff_r2w 3.manuf_type#c.diff_r2w /// 
		diff_indus_zoning c.diff_indus_zoning#c.invest_B ///
		diff_auto_roadnetwork 1.manuf_type#c.diff_auto_roadnetwork 3.manuf_type#c.diff_auto_roadnetwork ///
		diff_bad_bridges  ///
		diff_freightrail 1.manuf_type#c.diff_freightrail 3.manuf_type#c.diff_freightrail  ///
		diff_airport_any 1.manuf_type#c.diff_airport_any 3.manuf_type#c.diff_airport_any ///
		diff_occ_top2_naics3 c.diff_occ_top2_naics3#c.jobs_direct diff_pr_college ///
		1.manuf_type#c.diff_pr_college 3.manuf_type#c.diff_pr_college /// 
		diff_perc_est_n4 1.manuf_type#c.diff_perc_est_n4 3.manuf_type#c.diff_perc_est_n4 ///
		jobs_direct invest_B  mult_jobs income_tax corp_tax sales_tax proptax  /// 
		ln_pinc  incwage_top_5 c.incwage_top_5#c.ln_pinc  unemp c.unemp#c.jobs_direct term_limit min_mindist present density) ///
		varlabels(c.diff_corp_tax#c.invest_B "\hspace{4mm} $\times$ Investment Planned (\\$ B)" ///
			c.diff_income_tax#c.jobs_direct "\hspace{4mm} $\times$ Jobs Promised (1,000)" ///
			c.diff_proptax#c.invest_B "\hspace{4mm} $\times$ Investment Planned (\\$ B)" ///
			c.diff_wage#c.jobs_direct "\hspace{4mm} $\times$ Jobs Promised (1,000)" ///
			c.diff_e_ind#c.invest_B "\hspace{4mm} $\times$ Investment Planned (\\$ B)" ///
			1.manuf_type#c.diff_auto_roadnetwork "\hspace{4mm} $\times$ High-Tech Manufacturing"  ///
			3.manuf_type#c.diff_auto_roadnetwork "\hspace{4mm} $\times$ Traditional Manufacturing" ///
			1.manuf_type#c.diff_FHFA "\hspace{4mm} $\times$ High-Tech Manufacturing"  ///
			3.manuf_type#c.diff_FHFA "\hspace{4mm} $\times$ Traditional Manufacturing" ///
			1.manuf_type#c.diff_r2w "\hspace{4mm} $\times$ High-Tech Manufacturing"  ///
			3.manuf_type#c.diff_r2w "\hspace{4mm} $\times$ Traditional Manufacturing" ///
			c.diff_indus_zoning#c.invest_B "\hspace{4mm} $\times$ Investment Planned (\\$ B)" ///
			1.manuf_type#c.diff_freightrail "\hspace{4mm} $\times$ High-Tech Manufacturing"  ///
			3.manuf_type#c.diff_freightrail "\hspace{4mm} $\times$ Traditional Manufacturing" ///
			1.manuf_type#c.diff_airport_any "\hspace{4mm} $\times$ High-Tech Manufacturing"  ///
			3.manuf_type#c.diff_airport_any "\hspace{4mm} $\times$ Traditional Manufacturing" ///
			c.diff_occ_top2_naics3#c.jobs_direct "\hspace{4mm} $\times$ Jobs Promised (1,000)" ///
			1.manuf_type#c.diff_pr_college "\hspace{4mm} $\times$ High-Tech Manufacturing"  ///
			3.manuf_type#c.diff_pr_college "\hspace{4mm} $\times$ Traditional Manufacturing" ///
			1.manuf_type#c.diff_perc_est_n4 "\hspace{4mm} $\times$ High-Tech Manufacturing"  ///
			3.manuf_type#c.diff_perc_est_n4 "\hspace{4mm} $\times$ Traditional Manufacturing" ///
			c.incwage_top_5#c.ln_pinc "\hspace{4mm} $\times$ Log(Personal Income per Capita)" ///
			c.unemp#c.jobs_direct "\hspace{4mm} $\times$ Jobs Promised (1,000)" ) ///
		refcat(diff_corp_tax "\textbf{Profit Function:}" ///
		jobs_direct "\textbf{Runner-up Valuation:}" , nolabel)		 alignment(r)


label var diff_sh_occ "$\Delta$ Population in Relevant Occupations (\%)"
		
eststo clear 
************START WITH ALL POSSIBLE VARIABLES 
eststo: reg sub_M ///
c.diff_corp_tax diff_income_tax c.diff_proptax c.diff_sales_tax  /// taxes
c.diff_FHFA diff_incwage  c.diff_e_comm /// costs 
diff_indus_zoning diff_r2w /// regulations 
c.diff_auto_roadnetwork   c.diff_airport_any /// logistics/infrastructure
c.diff_pr_college c.diff_top_RD diff_sh_occ /// skilled labor
c.diff_perc_est_n4  /// agglomeration/suppliers  
 jobs_direct mult_tot invest_B income_tax corp_tax sales_tax proptax term_limit incwage_top_5 ln_pinc  unemp c.unemp#c.jobs_direct c.incwage_top_5#c.ln_pinc min_mindist present density [pw=weight] if ru_limit==1 & manuf==0  & sub_M<400, noconstant robust
 estadd scalar obs = 177
 
**** EXPERIMENT WITH INTERACTIONS 
eststo: reg sub_M ///
c.diff_corp_tax diff_income_tax c.diff_proptax diff_sales_tax   /// taxes
c.diff_corp_tax#c.invest_B c.diff_income_tax#c.jobs_direct c.diff_proptax#c.invest_B  /// taxes
c.diff_FHFA c.diff_e_comm /// costs 
c.diff_FHFA#c.invest_B c.diff_incwage_top_5#i.low_serv c.diff_e_comm#c.invest_B /// costs 
c.diff_indus_zoning c.diff_indus_zoning#c.invest_B c.diff_r2w /// regulations 
c.diff_auto_roadnetwork  c.diff_airport_any#i.trade /// logistics/infrastructure
c.diff_pr_college#i.low_serv c.diff_sh_occ#i.trade c.diff_top_RD#i.trade /// skilled labor
c.diff_perc_est_n4#i.low_serv  /// agglomeration/suppliers  
 jobs_direct mult_tot  invest_B income_tax corp_tax sales_tax proptax term_limit  unemp c.unemp#c.jobs_direct c. incwage_top_5 ln_pinc c.incwage_top_5#c.ln_pinc min_mindist present density [pw=weight] if ru_limit==1 & manuf==0  & sub_M<400, noconstant robust
 estadd scalar obs = 177

**** PARE DOWN
eststo: reg sub_M ///
c.diff_corp_tax diff_income_tax c.diff_proptax   /// taxes
 c.diff_income_tax#c.jobs_direct  /// taxes
c.diff_incwage_top_5#i.low_serv diff_FHFA c.diff_FHFA#c.invest_B c.diff_e_comm  /// costs 
 c.diff_r2w /// regulations 
c.diff_auto_roadnetwork c.diff_airport_any#1.trade /// logistics/infrastructure
 c.diff_top_RD#i.trade  /// skilled labor
 c.jobs_direct mult_tot  c.invest_B income_tax corp_tax sales_tax proptax term_limit  unemp  incwage_top_5 ln_pinc  [pw=weight] if ru_limit==1 & manuf==0  & sub_M<400, noconstant robust
 estadd scalar obs = 177

esttab using "$appxdir/OLS_spec_serv.tex", replace ///
		cells(b(star fmt(%-10.2fc)) & se(par fmt(%-10.2fc))) ///
		stats(obs r2 , fmt(%9.0fc %-10.3fc )	///
		labels( "Observations" "R-squared"))	///
		collabels(none) mlabels(none) label ///
		keep(diff_corp_tax c.diff_corp_tax#c.invest_B diff_income_tax c.diff_income_tax#c.jobs_direct /// 
		diff_proptax c.diff_proptax#c.invest_B diff_sales_tax /// 
		diff_incwage_top_5 0.low_serv#c.diff_incwage_top_5 1.low_serv#c.diff_incwage_top_5  diff_e_comm c.diff_e_comm#c.invest_B ///
		diff_FHFA c.diff_FHFA#c.invest_B /// 
		diff_r2w   /// 
		diff_indus_zoning c.diff_indus_zoning#c.invest_B ///
		diff_auto_roadnetwork   ///
		diff_airport_any 1.trade#c.diff_airport_any 0.trade#c.diff_airport_any  ///
		diff_sh_occ 1.trade#c.diff_sh_occ 0.trade#c.diff_sh_occ  ///
		diff_top_RD 1.trade#c.diff_top_RD 0.trade#c.diff_top_RD ///
		diff_pr_college 0.low_serv#c.diff_pr_college 1.low_serv#c.diff_pr_college /// 
		diff_perc_est_n4 1.low_serv#c.diff_perc_est_n4 0.low_serv#c.diff_perc_est_n4 ///
		jobs_direct mult_total invest_B income_tax corp_tax sales_tax proptax term_limit ln_pinc  /// 
		incwage_top_5 unemp c.unemp#c.jobs_direct c.incwage_top_5#c.ln_pinc min_mindist present density) ///
		order(diff_corp_tax c.diff_corp_tax#c.invest_B diff_income_tax c.diff_income_tax#c.jobs_direct /// 
		diff_proptax c.diff_proptax#c.invest_B diff_sales_tax /// 
		diff_incwage_top_5  0.low_serv#c.diff_incwage_top_5 1.low_serv#c.diff_incwage_top_5  diff_e_comm c.diff_e_comm#c.invest_B ///
		diff_FHFA c.diff_FHFA#c.invest_B /// 
		diff_r2w   /// 
		diff_indus_zoning c.diff_indus_zoning#c.invest_B ///
		diff_auto_roadnetwork  ///
		diff_airport_any 1.trade#c.diff_airport_any 0.trade#c.diff_airport_any  ///
		diff_sh_occ 1.trade#c.diff_sh_occ 0.trade#c.diff_sh_occ  ///
		diff_top_RD 1.trade#c.diff_top_RD 0.trade#c.diff_top_RD ///
		diff_pr_college 0.low_serv#c.diff_pr_college 1.low_serv#c.diff_pr_college /// 
		diff_perc_est_n4  0.low_serv#c.diff_perc_est_n4 1.low_serv#c.diff_perc_est_n4 ///
		jobs_direct mult_total invest_B income_tax corp_tax sales_tax proptax term_limit unemp /// 	
		c.unemp#c.jobs_direct ln_pinc  /// 
		incwage_top_5  c.incwage_top_5#c.ln_pinc min_mindist present density) ///
			refcat(diff_corp_tax "\textbf{Profit Function:}" ///
		jobs_direct "\textbf{Runner-up Valuation:}" , nolabel)		 alignment(r) ///
		varlabels(c.diff_corp_tax#c.invest_B "\hspace{4mm} $\times$ Investment Planned (\\$ B)" ///
			c.diff_income_tax#c.jobs_direct "\hspace{4mm} $\times$ Jobs Promised (1,000)" ///
			c.diff_proptax#c.invest_B "\hspace{4mm} $\times$ Investment Planned (\\$ B)" ///
			0.low_serv#c.diff_incwage_top_5 "\hspace{4mm} $\times$ High-Skill Services" ///
			1.low_serv#c.diff_incwage_top_5 "\hspace{4mm} $\times$ Trade and Other Services" ///
			c.diff_e_comm#c.invest_B "\hspace{4mm} $\times$ Investment Planned (\\$ B)" ///
			c.diff_FHFA#c.invest_B  "\hspace{4mm} $\times$ Investment Planned (\\$ B)"  ///
			c.diff_indus_zoning#c.invest_B "\hspace{4mm} $\times$ Investment Planned (\\$ B)" ///
			1.trade#c.diff_airport_any "\hspace{4mm} $\times$ Trade"  ///
			0.trade#c.diff_airport_any "\hspace{4mm} $\times$ Services" ///
			1.trade#c.diff_sh_occ "\hspace{4mm} $\times$ Trade" ///
			0.trade#c.diff_sh_occ "\hspace{4mm} $\times$ Services" ///
			1.trade#c.diff_top_RD "\hspace{4mm} $\times$ Trade" ///
			0.trade#c.diff_top_RD "\hspace{4mm} $\times$ Services" ///
			1.low_serv#c.diff_pr_college "\hspace{4mm} $\times$ Trade and Other Services" ///
			0.low_serv#c.diff_pr_college "\hspace{4mm} $\times$ High-Skill Services" ///
			1.low_serv#c.diff_perc_est_n4 "\hspace{4mm} $\times$ Trade and Other Services" ///
			0.low_serv#c.diff_perc_est_n4 "\hspace{4mm} $\times$ High-Skill Services" ///
			c.incwage_top_5#c.ln_pinc "\hspace{4mm} $\times$ Log(Personal Income per Capita)" ///
			c.unemp#c.jobs_direct "\hspace{4mm} $\times$ Jobs Promised (1,000)" ) 
			

*************************************************************************************
*Table K.1: Model Fit: Winning Locations 
*************************************************************************************
insheet using $datadir/modelfit_winninglocations.csv, comma clear 

keep state perc_* 
destring perc_loc, force replace 
recode perc_loc (.=0)

rename perc* perc*_manuf 

sa $temp/manuf, replace


insheet using $datadir/modelfit_winninglocations_serv.csv, comma clear 

keep state perc_* 
destring perc_loc, force replace 
recode perc_loc (.=0)

rename perc* perc*_serv

merge 1:1 stateabbrev using $temp/manuf, nogen 

sort state 
recode perc* (.=0) 


format perc_* %12.1fc

order state perc_loc_manuf perc_loc_sim_manuf perc_loc_serv perc_loc_sim_serv 

	* MAKE TABLE
	g tab = "\begin{tabular}{l|rr|rr}" in 1
	g top = "\toprule" in 1
	*Midrule
	g mid = " \midrule" in 1 
	g hline = " \hline" in 1 
	*Bottomrule
	g bot = "\bottomrule" in 1
	*End
	g end = "\end{tabular}" in 1
	*Panel

		g title1 = "  &  \multicolumn{2}{c|}{\textbf{Manufacturing}} & \multicolumn{2}{c}{\textbf{Services}} \\ " in 1
		g title2 = " State & \multicolumn{1}{c}{Data (\%)}  &  \multicolumn{1}{c|}{Simulated (\%)}  & \multicolumn{1}{c}{Data (\%)}  &  \multicolumn{1}{c}{Simulated (\%)} \\" in 1

	g c = " "

*****Output
	local filename = "modelfit_states_all"

	listtex tab if _n == 1 using "$appxdir/`filename'.tex", replace rstyle(none)
	listtex title1 if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)		
	listtex title2 if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)		
	listtex hline if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)		 
	listtex stateabbrev perc_loc_manuf perc_loc_sim_manuf perc_loc_serv perc_loc_sim_serv , appendto("$appxdir/`filename'.tex") rstyle(tabular)  
	listtex bot if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)	
	listtex end if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)	 
	

*********************************************************************************
*Table K.2 : Creating the Shortlist 
********************************************************************************
*SERVICES
********************************************************************************
u $datadir/analysis_cz_long, clear
keep if manuf==0 & sub_M<400 
drop if winner==1 
drop if pop<200000 & runnerup==0
replace pop=pop/1000000
drop if occ_top2_naics3<1 & runnerup==0
gsort id -perc_est_n4 
by id: drop if airport_any==0 & _n>50 & runnerup==0

foreach v in pop wage auto_roadnetwork airport_any r2w occ_top2_naics3 pr_college perc_est_n4 {
	g mean_`v'_1 = `v'
	g med_`v'_1 = `v'
}
drop *mindist 

g match=1 
collapse (mean) mean_* (p50) med_*, by(match)

sa $temp/serv_sl, replace 

u $datadir/analysis_cz_long, clear
keep if manuf==0 & sub_M<400 
keep if runnerup==1 
replace pop=pop/1000000

drop *mindist 
foreach v in pop wage auto_roadnetwork airport_any r2w occ_top2_naics3 pr_college perc_est_n4 {
	g mean_`v'_2= `v'
	g med_`v'_2 = `v'
}

g match=1 
collapse (mean) mean_* (p50) med_*, by(match)

merge 1:1 match using $temp/serv_sl, nogen 
sa $temp/serv_sl, replace 

u $datadir/analysis_cz_long, clear
keep if manuf==0 & sub_M<400 
keep if winner==1
replace pop=pop/1000000

drop *mindist 
foreach v in pop wage auto_roadnetwork airport_any r2w occ_top2_naics3 pr_college perc_est_n4 {
	g mean_`v'_3= `v'
	g med_`v'_3 = `v'
}

g match=1 
collapse (mean) mean_* (p50) med_*, by(match)

merge 1:1 match using $temp/serv_sl, nogen 


	* Make table
	format mean_* med_* %12.2fc

	* MAKE TABLE
	g tab = "\begin{tabular}{lrrrrrr}" in 1
	g top = "\toprule" in 1
	*Midrule
	g mid = " \midrule" in 1 
	g hline = " \hline" in 1 
	*Bottomrule
	g bot = "\bottomrule" in 1
	*End
	g end = "\end{tabular}" in 1
	*Panel

	g title1 = "  &  \multicolumn{2}{c}{Potential Shortlist} & \multicolumn{2}{c}{Runners-up}  & \multicolumn{2}{c}{Winners} \\ " in 1
	
		g title2 = " &  Mean & Med. & Mean & Med. & Mean & Med.  \\ " in 1

	g c = " "
	


g label_wage =  "Industry Wage (\\$1,000)"
g label_r2w = "Right-to-Work"
g label_auto_roadnetwork = "Auto Network Density"
g label_airport_any =  "Large Airport"
g label_pr_college = "Population with BA+ (\%)"
g label_perc_est_n4 = "Share Industry Establishments "
g label_occ_top2_naics3 = "Employment in Relevant Occupations (1,000)"
g label_pop = "Population (1,000,000)"



*****Output
	local filename = "shortlist_serv"

	listtex tab if _n == 1 using "$appxdir/`filename'.tex", replace rstyle(none)
	listtex title1 if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)		
	listtex title2 if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)	
	listtex hline if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)	 
	foreach v in pop wage auto_roadnetwork airport_any r2w occ_top2_naics3 pr_college perc_est_n4 {
		listtex label_`v' mean_`v'_1 med_`v'_1 mean_`v'_2  med_`v'_2   ///
		mean_`v'_3  med_`v'_3   ///
		, appendto("$appxdir/`filename'.tex") rstyle(tabular) 
		}
	listtex bot if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(tabular)	
	listtex end if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)	 
	
*********************************************************************************
*MANUFACTURING 
********************************************************************************
u $datadir/analysis_cz_long, clear
keep if manuf==1 & sub_M<1000 
drop if winner==1 
drop if pop<200000 & runnerup==0
replace pop=pop/1000000
drop if occ_top2_naics3<1 & runnerup==0
gsort id -perc_est_n4 
by id: drop if _n>100 & runnerup==0
by id: drop if _n>60 & runnerup==0 & r2w==0
by id: drop if _n>40 & runnerup==0 & r2w==0 & airport_any==0 

foreach v in pop wage auto_roadnetwork airport_any r2w occ_top2_naics3 pr_college perc_est_n4 {
	g mean_`v'_1 = `v'
	g med_`v'_1 = `v'
}
drop *mindist 

g match=1 
collapse (mean) mean_* (p50) med_*, by(match)

sa $temp/manuf_sl, replace 

u $datadir/analysis_cz_long, clear
keep if manuf==1 & sub_M<1000 
keep if runnerup==1 
replace pop=pop/1000000

drop *mindist 
foreach v in pop wage auto_roadnetwork airport_any r2w occ_top2_naics3 pr_college perc_est_n4 {
	g mean_`v'_2= `v'
	g med_`v'_2 = `v'
}

g match=1 
collapse (mean) mean_* (p50) med_*, by(match)

merge 1:1 match using $temp/manuf_sl, nogen 
sa $temp/m_sl, replace 

u $datadir/analysis_cz_long, clear
keep if manuf==1 & sub_M<1000 
keep if winner==1
replace pop=pop/1000000

drop *mindist 
foreach v in pop wage auto_roadnetwork airport_any r2w occ_top2_naics3 pr_college perc_est_n4 {
	g mean_`v'_3= `v'
	g med_`v'_3 = `v'
}

g match=1 
collapse (mean) mean_* (p50) med_*, by(match)

merge 1:1 match using $temp/m_sl, nogen 


	* Make table
	format mean_* med_* %12.2fc

	* MAKE TABLE
	g tab = "\begin{tabular}{lrrrrrr}" in 1
	g top = "\toprule" in 1
	*Midrule
	g mid = " \midrule" in 1 
	g hline = " \hline" in 1 
	*Bottomrule
	g bot = "\bottomrule" in 1
	*End
	g end = "\end{tabular}" in 1
	*Panel

	g title1 = "  &  \multicolumn{2}{c}{Potential Shortlist} & \multicolumn{2}{c}{Runners-up}  & \multicolumn{2}{c}{Winners} \\ " in 1
	
		g title2 = " &  Mean & Med. & Mean & Med. & Mean & Med.  \\ " in 1

	g c = " "
	
g label_wage =  "Industry Wage (\\$1,000)"
g label_r2w = "Right-to-Work"
g label_auto_roadnetwork = "Auto Network Density"
g label_airport_any =  "Large Airport"
g label_pr_college = "Population with BA+ (\%)"
g label_perc_est_n4 = "Share Industry Establishments "
g label_occ_top2_naics3 = "Employment in Relevant Occupations (1,000)"
g label_pop = "Population (1,000,000)"

*****Output
	local filename = "shortlist_manuf"

	listtex tab if _n == 1 using "$appxdir/`filename'.tex", replace rstyle(none)
	listtex title1 if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)		
	listtex title2 if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)	
	listtex hline if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)	 
	foreach v in pop wage auto_roadnetwork airport_any r2w occ_top2_naics3 pr_college perc_est_n4 {
		listtex label_`v' mean_`v'_1 med_`v'_1 mean_`v'_2  med_`v'_2   ///
		mean_`v'_3  med_`v'_3   ///
		, appendto("$appxdir/`filename'.tex") rstyle(tabular) 
		}
	listtex bot if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(tabular)	
	listtex end if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)	 
	
			
*******************************************************************************
*Table K.3: Welfare Analysis by Sector 
*******************************************************************************
*simulated pi and v in winning places: 
insheet using $datadir/cf_locations.csv, comma clear 
keep if winner==1 
destring sub_m, force replace 
collapse (sum) mean_v mean_pi sub_m share
g type="real"
sa $temp/real_manuf, replace 

insheet using $datadir/cf_locations_serv.csv, comma clear 
keep if winner==1 
destring sub_m, force replace 
collapse (sum) mean_v mean_pi sub_m share
g type="real"
sa $temp/real_serv, replace 

************************************************************
*simulated pi and v in counterfactual places: 
insheet using $datadir/cf_locations.csv, comma clear 
collapse (sum) adj_v adj_pi 
g type="cf"
sa $temp/cf_manuf, replace 

insheet using $datadir/cf_locations_serv.csv, comma clear 
collapse (sum) adj_v adj_pi 
g type="cf"
sa $temp/cf_serv, replace 


u $temp/real_manuf, clear
append using $temp/cf_manuf 
g manuf=1 
append using $temp/real_serv
append using $temp/cf_serv 
recode manuf(.=0)

g v = mean_v 
replace v = adj_v if v==. 
g pi = mean_pi 
replace pi = adj_pi if pi==. 

replace v = v/1000
replace pi = pi/1000
replace sub = sub/1000

g policy =  "Subsidy Ban" if type=="cf"
replace policy = "Competition" if type == "real"
drop type 

recode sub_m (.=0)
g state_payoff = v-sub
g firm_payoff = pi + sub
g total_welfare = v + pi 

g sector = "Manufacturing"
replace sector = "Trade/Services" if manuf==0
drop manuf 

gsort sector -policy 

order sector policy v pi sub_m state_payoff firm_payoff total_welfare 

	g sector_lab = "\textbf{Manufacturing:}" in 1 
		replace sector_lab = "\textbf{Trade/Services:}" in 3 

foreach v in state_payoff firm_payoff total_welfare {
		by sector: g `v'_change = 100*(`v'[2] - `v'[1])/(`v'[1]) 
}
format v pi sub_m state_payoff* firm_payoff* total_welfare* %12.1fc
tostring state_payoff_change firm_payoff_change total_welfare_change, force usedisplayformat replace 

foreach v in state_payoff firm_payoff total_welfare {
	replace `v'_change = `v'_change + "\%" 
}

	* MAKE TABLE
	g tab = "\begin{tabular}{rc|rr|r|rr|r}" in 1
	g top = "\toprule" in 1
	*Midrule
	g mid = " \midrule" in 1 
	g hline = " \hline" in 1 
	*Bottomrule
	g bot = "\bottomrule" in 1
	*End
	g end = "\end{tabular}" in 1
	*Panel
	
	g line3text = "\multicolumn{5}{r|}{\textit{$\Delta$ welfare from competition:}} " 

		g title1 = " & &  \multicolumn{2}{c|}{Simulated} & Sub  &  \multicolumn{2}{c|}{Payoffs (\\$ \hspace{-1mm}B)} & \multicolumn{1}{c}{Total} \\ " in 1
		g title2 = "  & \multicolumn{1}{c|}{Policy}& \multicolumn{1}{c}{$ v $ (\\$ \hspace{-1mm}B)}   &  \multicolumn{1}{c|}{$\pi$ (\\$ \hspace{-1mm}B)} & \multicolumn{1}{c|}{(\\$ \hspace{-1mm}B)}  & \multicolumn{1}{c}{States} & \multicolumn{1}{c|}{Firms}  & \multicolumn{1}{c}{Welfare} \\ " in 1

	g c = " "

*****Output
	local filename = "counter_v_app"

	listtex tab if _n == 1 using "$appxdir/`filename'.tex", replace rstyle(none)
	listtex title1 if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)		
	listtex title2 if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)		
	listtex hline if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)		 
	listtex sector_lab  policy  v pi sub_m state_payoff firm_payoff total_welfare if sector=="Manufacturing", appendto("$appxdir/`filename'.tex") rstyle(tabular) 
				listtex hline if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)	
	listtex line3text state_payoff_change firm_payoff_change total_welfare_change if _n==2, appendto("$appxdir/`filename'.tex") rstyle(tabular) 
	listtex hline if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)	
	listtex sector_lab policy  v pi sub_m state_payoff firm_payoff total_welfare  if sector=="Trade/Services", appendto("$appxdir/`filename'.tex") rstyle(tabular) 
				listtex hline if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)	
	listtex line3text state_payoff_change firm_payoff_change total_welfare_change if _n==4, appendto("$appxdir/`filename'.tex") rstyle(tabular) 
			listtex hline if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)	
	listtex end if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)	 

*********************************************************************************
*Table K.4 Welfare Analysis: No Random Coefficients
*********************************************************************************
*simulated pi and v in winning places: 
insheet using $datadir/cf_locations_norc.csv, comma clear 
keep if winner==1 
destring *, force replace 
collapse (sum) mean_v mean_pi sub_m (p50) share
g type="real"
sa $temp/real_manuf, replace 

insheet using $datadir/cf_locations_serv_norc.csv, comma clear 
keep if winner==1 
destring *, force replace 
collapse (sum) mean_v mean_pi sub_m (p50) share
g type="real"
sa $temp/real_serv, replace 

append using $temp/real_manuf 
collapse (sum) mean_v mean_pi sub_m (mean) share , by(type)

rename mean_* * 
sa $temp/real, replace 
************************************************************
*simulated pi and v in counterfactual places: 
insheet using $datadir/cf_locations_norc.csv, comma clear 
destring *, force replace 
collapse (sum) adj_v adj_pi 
g type="cf"
sa $temp/cf_manuf, replace 

insheet using $datadir/cf_locations_serv_norc.csv, comma clear 
destring *, force replace 
collapse (sum) adj_v adj_pi 
g type="cf"
sa $temp/cf_serv, replace 

append using $temp/cf_manuf 
collapse (sum) adj_v adj_pi, by(type)
sa $temp/cf, replace 

rename adj_* *

append using $temp/real 

replace pi = pi/1000
replace v = v/1000
replace sub = sub/1000

g policy =  "Subsidy Ban" if type=="cf"
replace policy = "Competition" if type == "real"
drop type 
recode sub_ (.=0)

gsort -policy 
g state_payoff = v - sub
g firm_payoff = pi + sub
g total_welfare = v + pi 
g mover = 100-share

order policy v pi sub_m state_pay firm_payoff total 

set obs  3
foreach v in state_payoff firm_payoff total_welfare {
		replace `v' = 100*(`v'[2] - `v'[1])/(`v'[1]) in 3
}


	format mover v pi sub_m state_payoff firm_payoff total_welfare %12.1fc
	
g line3text = "\multicolumn{5}{r|}{\textit{$\Delta$ welfare from competition:}} "

tostring state_payoff firm_payoff total_welfare mover, force usedisplayformat replace 

foreach v in state_payoff firm_payoff total_welfare {
	replace `v' = `v' + "\%" in 3
}

replace mover = mover + "\%"
replace mover = "\multicolumn{1}{c|}{-}" if policy=="Subsidy Ban"
	
	* MAKE TABLE
	g tab = "\begin{tabular}{c|r|rr|r|rr|r}" in 1
	g top = "\toprule" in 1
	*Midrule
	g mid = " \midrule" in 1 
	g hline = " \hline" in 1 
	*Bottomrule
	g bot = "\bottomrule" in 1
	*End
	g end = "\end{tabular}" in 1
	*Panel

		g title1 = " & &  \multicolumn{2}{c|}{Simulated} & Sub  &  \multicolumn{2}{c|}{Payoffs (\\$ \hspace{-1mm}B)} & \multicolumn{1}{c}{Total} \\ " in 1
		g title2 = "  \multicolumn{1}{c|}{Policy}& \multicolumn{1}{c|}{Movers}& \multicolumn{1}{c}{$ v $ (\\$ \hspace{-1mm}B)}   &  \multicolumn{1}{c|}{$\pi$ (\\$ \hspace{-1mm}B)} & \multicolumn{1}{c|}{(\\$ \hspace{-1mm}B)}  & \multicolumn{1}{c}{States} & \multicolumn{1}{c|}{Firms}  & \multicolumn{1}{c}{Welfare} \\ " in 1

	g c = " "

*****Output
	local filename = "counter_v_norc"

	listtex tab if _n == 1 using "$appxdir/`filename'.tex", replace rstyle(none)
	listtex title1 if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)		
	listtex title2 if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)		
	listtex hline if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)		 
	listtex policy mover v pi sub_m state_pay firm_payoff total if _n<3, appendto("$appxdir/`filename'.tex") rstyle(tabular) 
	listtex hline if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)
		listtex line3text state_pay firm_payoff total if _n==3, appendto("$appxdir/`filename'.tex") rstyle(tabular) 
	listtex hline if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)
	listtex end if _n == 1, appendto("$appxdir/`filename'.tex") rstyle(none)	 
		
